#include <iostream>
#include <algorithm>
#include <iterator>

using namespace std;

#if 0
#define DEBUG
#endif


#define MAX_N 1001
float ans[MAX_N];
int n;

void Process() {
    int l2r[MAX_N];
    int r2l[MAX_N];
    std::fill(l2r, l2r+MAX_N, 1);
    std::fill(r2l, r2l+MAX_N, 1);

    int l2r_max = 0;
    for (int ni = 1; ni < n; ni++) {
        for (int i = 0; i < ni; ++i) {
            if(ans[ni] > ans[i]) {
                l2r[ni] = max<int>(l2r[ni], l2r[i]+1);
                if (l2r[ni] > l2r_max) l2r_max = l2r[ni];
            }
        }
    }
    int r2l_max = 0;
    for (int ni = n-1; ni >= 0; ni--) {
        for (int i = ni+1; i < n; ++i) {
            if(ans[ni] > ans[i]) {
                r2l[ni] = max<int>(r2l[ni], r2l[i]+1);
                if (r2l[ni] > r2l_max) r2l_max = r2l[ni];
            }
        }
    }
#ifdef DEBUG
    cout << "l2r_max: " << l2r_max << endl;
    std::copy(l2r, l2r+n, std::ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << "r2l_max: " << r2l_max << endl;
    std::copy(r2l, r2l+n, std::ostream_iterator<int>(cout, " "));
    cout << endl;
#endif
    int max_len = max<int>(l2r_max, r2l_max);
    for (int l = 0; l <= n-1; l++) {
        for (int r = l+1; r <= n-1; r++) {
            if (ans[r] > ans[l]) {
            }else if (max_len < l2r[l]+r2l[r]) 
            {
                max_len = l2r[l]+r2l[r];
            }
        }
    }
    cout << n - max_len << endl;
}

int main() {

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> ans[i];
    }
    Process();

    return 0;
}
